const Order = require('../model/order.model');
// const Food = require('../model/food.model')
// const User = require('../model/user.model');

class operationOrder {

	async findOrders(pageNum,pageSize) {
		const offset = (pageNum - 1) * pageSize
		const {count,rows} = await Order.findAndCountAll({
			// attributes:['order_num','order_price','order_status'],
			offset:offset,
			limit:pageSize * 1,
		})
		return {
			pageNum,
			pageSize,
			total:count,
			lists:rows
		}
	}

	async addOrder(order_id,food_id,{food_name,price,address},{id,user_name},{num,status}){
		const res = await Order.create({
			order_id,
			user_id:id,
			user_name,
			food_id,
			food_name,
			food_address:address,
			num,
			price:price * num,
			status,
		})
		return res.dataValues
	}

}

module.exports = new operationOrder()